<?php
/**
 * Dcolors,The Community Application for Web
 *
 * LoadFunction class
 *
 * Not free software
 * @author     chopin xiao <x@sunsne.com>
 * @copyright  2009 The Dcolors Group
 * @version    SVN: $Id: LoadFunction.php 15 2009-01-19 11:36:08Z chopins.xiao $
 **/

class LoadFunction
{
	public $object;
	public function __construct($obname,$mehod,$param)
	{
		$this->getObject($obname);
		return $this->getMethod($mehod,$param);
	}
	public function getObject($name)
	{
		if(file_exists(APP.'/Lib/'.$name.'.php'))
		{
			$this->object = new $name;
		}else{
			return false;
		}
	}
	public function getMethod($name,$params)
	{
		if(is_object($this->object))
		{
			if(is_array($params))
			{
				return call_user_func_array(array($this->objec,$name),$params);
			}
			return call_user_func(array($this->objec,$name),$params);
		}else{
			return false;
		}
	}
	public function __destruct()
	{
		$this->object = null;
	}
	public function LoadControl($name,$admin=false)
	{
		$con = $admin ? 'Admin': 'Front';
		if($admin && !$this->Permissions())
		{
			return false;
		}
		if(file_exists(APP."/Control/{$con}Control/{$name}.php"))
		{
			include_once(APP."/Control/{$con}Control/{$name}.php");
			return new $name;
		}else {
			return false;
		}
	}
	private function Permissions()
	{
		session_start();
		if(empty($_SESSION['admin']))
		{
			return false;
		}else{
			return true;
		}
	}
}